package com.bwie.controller;

import com.bwie.mapper.PackMapper;
import com.bwie.pojo.Park;
import com.bwie.utils.R;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author 冉申强
 * @version 1.0
 * @description: TODO
 * @date 2025/5/13 10:05
 */
@RestController
@RequestMapping("/user/user")
@Api(tags = "微服务")
@Slf4j
public class ParkController {
    @Autowired
    PackMapper packMapper;
    /**
    * //TODO 车辆入场管理
    * @description parkAdd
    * @params [park]
    * @return com.bwie.utils.R
    * @author 冉申强
    * @date 2025/5/13 11:48
     * @param park
     * @return com.bwie.utils.R
    */
    @ApiOperation("车辆入场管理")
    @PostMapping("parkAdd")
    public R parkAdd(@RequestBody Park park){
        park.setLicense("沪A18826");
            park.setTime(new Date());
            park.setTiming("2/小时");
        int insert = packMapper.insert(park);
        String token = Jwts.builder()
                .signWith(SignatureAlgorithm.HS256, "123456")
                .claim("id", park.getId())
                .compact();
        log.info("车辆入场管理"+insert);
        Park park1 = packMapper.selectById(1);
        park1.setToken(token);
        log.info("列表11----", park1);
        return R.OK(park1);
    }
    /**
    * //TODO 停车列表查询
    * @description parkList
    * @params []
    * @return com.bwie.utils.R
    * @author 冉申强
    * @date 2025/5/13 11:48
     * @return com.bwie.utils.R
    */
    @ApiOperation("停车列表查询")
    @PostMapping("parkList")
    public R parkList(){
        List<Park> parks = packMapper.selectList(null);
        log.info("停车列表查询"+parks);
        return R.OK(parks);
    }
    /**
    * //TODO 停车费用计算
    * @description parkUpdate
    * @params [park]
    * @return com.bwie.utils.R
    * @author 冉申强
    * @date 2025/5/13 11:48
     * @param park
     * @return com.bwie.utils.R
    */
    @ApiOperation("停车费用计算")
    @PostMapping("parkUpdate")
    public R parkUpdate(@RequestBody Park park){
        park.setId(1);
        park.setState("已缴费");
        park.setTime(new Date());
        int insert = packMapper.updateById(park);
        log.info("停车费用计算"+insert);
        return R.OK(insert);
    }
    /**
    * //TODO 车辆离场处理
    * @description parkDEl
    * @params [park]
    * @return com.bwie.utils.R
    * @author 冉申强
    * @date 2025/5/13 11:48
     * @param park
     * @return com.bwie.utils.R
    */
    @ApiOperation("车辆离场处理")
    @PostMapping("parkDEl")
    public R parkDEl(@RequestBody Park park){
        park.setId(2);
        int insert = packMapper.deleteById(park);
        log.info("车辆离场处理"+insert);
        return R.OK(insert);
    }
}
